package com.mykong.core;

import org.springframework.context.ApplicationContext;
import org.springframework.context.support.GenericXmlApplicationContext;
import org.springframework.data.mongodb.core.MongoOperations;
import org.springframework.data.mongodb.core.query.Criteria;
import org.springframework.data.mongodb.core.query.Query;
import org.springframework.data.mongodb.core.query.Update;

import com.mykong.user.User;

public class App {

	public static void main(String[] args) {
		
		ApplicationContext ctx = new GenericXmlApplicationContext("mongo-config.xml");
		MongoOperations mongoOperation = (MongoOperations)ctx.getBean("mongoTemplate");
		
		User user = new User("david", "pass");
		
		//save
		mongoOperation.save(user, "users");
		
		//find
		User savedUser = mongoOperation.findOne(new Query(Criteria.where("username").regex("dav")), User.class, "users");
		System.out.println("savedUser: " + savedUser);
		
		//update
		//mongoOperation.updateMulti(new Query(Criteria.where("username").is("david")), Update.update("password", "new pass"), "users");

	}

}
